<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<div class="box box-primary">
  <div class="box-header with-border">
  </div><!-- /.box-header -->
  <!-- form start -->
  <form action="/resource/resUpload" name="form-file" id="form-file"  enctype="multipart/form-data" method="post" role="form">
    <div class="box-body">
      <div class="form-group">
        <label for="file">选择文件上传</label>
        <input type="file" id="file" name="file">
        <p class="help-block text-red">请先选择文件上传再填写下方表单！</p>
      </div>
    </div><!-- /.box-body -->

    <div class="box-footer">
      <button type="button" class="btn btn-primary" id="btn-file-upload" onclick="return doUpload()">上传</button>
    </div>
  </form>
  <script>
  function doUpload() {
	if ($('input#file').val() == '')
    {
      console.log('empty file');
      swal('没有选择文件', '', 'error');
      return false;
    }
    var formData = new FormData($("#form-file")[0]);
    console.log($("#form-file")[0]);
    console.log(formData)
    $.ajax({
         url: '/resource/resUpload' ,
         type: 'POST',
         data: formData,
         async: false,
         cache: false,
         contentType: false,
         processData: false,
         success: function (ret) {
        	 console.log(ret);
         },
         error: function (ret) {
         }
    });
    return false;
  }
  </script>
</div>